home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_02 / labrocca / arch.c < prev    next >
C/C++ Source or Header  |  1993-12-01  |  3KB  |  103 lines

  1. /* Listing 2 */
  2. /* ARCH.C */
  3. /*  Copyright 1993 by P.J. LaBrocca
  4.     All rights reserved.
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10.  
  11. #include "sea.h"
  12.  
  13. /* Forms a filename plus extension,
  14.    if any, from the full or partial path
  15.    pointed to by path and stores it in
  16.    buffer pointed to by name.
  17. */
  18. char *filename( char *path, char *name )
  19. {
  20.     char *p;
  21.  
  22.     /* Start at last character */
  23.     p = path + strlen( path ) - 1;
  24.     while( p != path ) {
  25.         if( *p == '\\' || *p == ':' )
  26.             break;
  27.         --p;
  28.     }
  29.     if( p == path && *p != '\\')
  30.         strcpy( name, path );
  31.     else
  32.         strcpy( name, ++p );
  33.     return name;
  34. }
  35.  
  36. void main( int argc, char **argv )
  37. {
  38.     FILE *input, *output;
  39.     int c;
  40.     int count = 1;
  41.     HEADER header;
  42.     long i;
  43.     /* char extension[5];  for _splitpath() */
  44.  
  45.     if( argc == 1 ) {
  46.         printf("Usage: arch file [file ...]\n");
  47.         printf("    Wild cards * and ?.\n");
  48.         exit( 0 );
  49.     }    
  50.  
  51. /* open extractor module */
  52.     if((input = fopen("extr.exe", "rb")) == NULL) {
  53.         printf( "error opening extr.exe\n" );
  54.         exit( 0 );
  55.     } /* if( ( archive = */
  56.  
  57. /* open the final archive file */
  58.     if((output = fopen("out.exe", "wb")) == NULL) {
  59.         printf( "error opening output\n" );
  60.         exit( 0 );
  61.     } /* if( ( output =  */
  62.  
  63. /* copy extractor to final output file */
  64.     while( ( c = getc( input ) ) != EOF ) {
  65.         putc( c, output );
  66.     } /* while( ( c = */
  67.  
  68.     fclose( input );
  69.  
  70.     while( count < argc ) {
  71.         if((input = fopen( argv[count], "rb"))==NULL) {
  72.             printf( "Can't open %s\n", argv[count] );
  73.             ++count;
  74.             continue;
  75.         } /* if( ( input = */
  76.         printf( "Adding %-15s", argv[count] );
  77.         fseek( input, 0, SEEK_END );
  78.         header.filesize = ftell( input );
  79.         fseek( input, 0, SEEK_SET );
  80.  
  81. #if 0
  82.         _splitpath( argv[count], NULL, NULL,
  83.                     header.filename, extension );
  84.         strcat( header.filename, extension );
  85. #endif
  86.         filename( argv[count], header.filename );
  87.  
  88.         fwrite( &header, sizeof( HEADER ), 1, output );
  89.  
  90.         for( i = 0; i < header.filesize; ++i ) {
  91.             putc( getc( input ), output );
  92.         } /* for( i = 0; i < */
  93.         fclose( input );
  94.         printf("Done!\n");
  95.         ++count;
  96.     } /* while(  ) */
  97.     header.filesize = -1L;
  98.     fwrite( &header, sizeof( HEADER ), 1, output );
  99.     fclose( output );
  100. } /* main */
  101.  
  102. /* End of File */
  103.